{% extends "base.html" %}
{% block body %}
<br>
<button class="btn btn{{config['outline-buttons']}}info" onclick="get_task_by_attack()">Tasks by ATT&CK</button> <!-- shows a matrix with numbers-->
<button class="btn btn{{config['outline-buttons']}}info" onclick="get_command_by_attack()">Commands by ATT&CK</button> <!-- shows a matrix with numbers -->
<button class="btn btn{{config['outline-buttons']}}info" onclick="output_to_navigator()">Output to ATT&CK Navigator</button> <!-- outputs a JSON file for ATT&CK Navigator -->
<br><br>
<div class="input-group mb-3" id="regexGroup">
    <input id="regex" type="text" class="form-control" style="position:relative;display:inline-block" placeholder="input regex to match tasks" v-model="regex" @keyup.enter="submit_search()">
    <select id="attackOptions" v-model="selected" class="form-control">
        <option v-for="tech in options" :value="tech.t_num">[[tech.t_num]] [[tech.name]]</option>
    </select>
    <template v-if="finalize">
        <button type="button" class="btn btn{{config['outline-buttons']}}warning" @click="submit_search()">Assign</button>
    </template>
    <template v-else>
        <button type="button" class="btn btn{{config['outline-buttons']}}primary" @click="submit_search()">Match </button>
    </template>

    <span class="input-group-append">
        <span class="input-group-text">Finalize?&nbsp;&nbsp;</span>
    </span>
    <span class="input-group-append">
        <span class="material-switch input-group-text">
            <input class="form-control" type="checkbox" v-model="finalize" id="finalize">
            <label for="finalize" class="btn-warning input-group-append"></label>
        </span>
    </span>
</div>
<div id="regexOutput">
    <div style="resize: vertical; overflow:auto;" class="card border border-dark shadow" v-if="tasks.length > 0">
        <div class="card-header bg-header text-white"><h4>Matching Tasks</h4></div>
        <table width="100%" border="2px" style="table-layout:fixed;word-wrap: break-word;margin:0;padding:0" class="table table-striped {{config['table-color']}}">
            <tr>
                <th style="text-align:left;width:10em"><b>Task Number</b></th>
                <th style="text-align:left"><b>Task</b></th>
                <th style="text-align:left"><b>Current ATT&CK Mappings</b></th>
            </tr>
            <template v-for="t in tasks">
                <tr>
                    <td style="text-align:left;width:7em">&nbsp;&nbsp;<b><a :href="t.href" target="_blank">[[t.id]]</a></b></td>
                    <td style="text-align:left">
                            [[t.command]] [[t.original_params ]]
                    </td>
                    <td style="text-align:left">
                        <template v-for="a in t.attack">
                            [[a.t_num]] [[a.name]]<br>
                        </template>
                    </td>
                </tr>
            </template>
        </table>
    </div><br>

</div>
<div id="attack_matrix">
    <table width="100%" style="border-spacing: 5px;border-collapse: separate;table-layout:fixed;word-wrap: break-word" class="table-striped {{config['table-color']}} table">
        <tr >
            <th style="text-align:center"><b>Initial Access</b></th>
            <th style="text-align:center"><b>Execution</b></th>
            <th style="text-align:center"><b>Persistence</b></th>
            <th style="text-align:center"><b>Privilege Escalation</b></th>
            <th style="text-align:center"><b>Defense Evasion</b></th>
            <th style="text-align:center"><b>Credential Access</b></th>
            <th style="text-align:center"><b>Discovery</b></th>
            <th style="text-align:center"><b>Lateral Movement</b></th>
            <th style="text-align:center"><b>Collection</b></th>
            <th style="text-align:center"><b>Exfiltration</b></th>
            <th style="text-align:center"><b>Command and Control</b></th>
            <th style="text-align:center"><b>Impact</b></th>
        </tr>
        <tr v-for="(index, i) in matrix_length">
            <td style="text-align:center">
                <template v-if="matrix['initial-access'][index-1].name != ''">
                    <button @click="view_data('initial-access', index-1)" :style="Object.keys(matrix['initial-access'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['initial-access'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['initial-access'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['execution'][index-1].name != ''">
                    <button @click="view_data('execution', index-1)" :style="Object.keys(matrix['execution'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['execution'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['execution'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['persistence'][index-1].name != ''">
                    <button @click="view_data('persistence', index-1)" :style="Object.keys(matrix['persistence'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['persistence'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['persistence'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['privilege-escalation'][index-1].name != ''">
                    <button @click="view_data('privilege-escalation', index-1)" :style="Object.keys(matrix['privilege-escalation'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['privilege-escalation'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['privilege-escalation'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['defense-evasion'][index-1].name != ''">
                    <button @click="view_data('defense-evasion', index-1)" :style="Object.keys(matrix['defense-evasion'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['defense-evasion'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['defense-evasion'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['credential-access'][index-1].name != ''">
                    <button @click="view_data('credential-access', index-1)" :style="Object.keys(matrix['credential-access'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['credential-access'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['credential-access'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['discovery'][index-1].name != ''">
                    <button @click="view_data('discovery', index-1)" :style="Object.keys(matrix['discovery'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['discovery'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['discovery'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['lateral-movement'][index-1].name != ''">
                    <button @click="view_data('lateral-movement', index-1)" :style="Object.keys(matrix['lateral-movement'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['lateral-movement'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['lateral-movement'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['collection'][index-1].name != ''">
                    <button @click="view_data('collection', index-1)" :style="Object.keys(matrix['collection'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['collection'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['collection'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['exfiltration'][index-1].name != ''">
                    <button @click="view_data('exfiltration', index-1)" :style="Object.keys(matrix['exfiltration'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['exfiltration'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['exfiltration'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['command-and-control'][index-1].name != ''">
                    <button @click="view_data('command-and-control', index-1)" :style="Object.keys(matrix['command-and-control'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['command-and-control'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['command-and-control'][index-1].name ]]
                </template>
            </td>
            <td style="text-align:center">
                <template v-if="matrix['impact'][index-1].name != ''">
                    <button @click="view_data('impact', index-1)" :style="Object.keys(matrix['impact'][index-1]['mappings']).length > 0 ? 'background-color: #c63f1e;color:white;width:100%;height:100%;border:none' : ''" class="btn btn-mitre">[[ matrix['impact'][index-1].name ]]</button>
                </template>
                <template v-else>
                    [[ matrix['impact'][index-1].name ]]
                </template>
            </td>
        </tr>
    </table>
</div>
<div id="MITRELicense">
    <p style="white-space: pre-wrap"><font size="0.25">
LICENSE
The MITRE Corporation (MITRE) hereby grants you a non-exclusive, royalty-free license to use ATT&CK™ for research, development, and commercial purposes. Any copy you make for such purposes is authorized provided that you reproduce MITRE's copyright designation and this license in any such copy.
"© 2018 The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation."
DISCLAIMERS
MITRE does not claim ATT&CK enumerates all possibilities for the types of actions and behaviors documented as part of its adversary model and framework of techniques. Using the information contained within ATT&CK to address or cover full categories of techniques will not guarantee full defensive coverage as there may be undisclosed techniques or variations on existing techniques not documented by ATT&CK.
ALL DOCUMENTS AND THE INFORMATION CONTAINED THEREIN ARE PROVIDED ON AN "AS IS" BASIS AND THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE MITRE CORPORATION, ITS BOARD OF TRUSTEES, OFFICERS, AGENTS, AND EMPLOYEES, DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION THEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
    </font></p></div>
<!-- THIS IS OUR MODEL FOR CLICKED ATT&CK BUTTON -->
<div class="modal fade" id="showATTACKDataModal" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3>[[cell_data.name]] ([[cell_data.t_num]] ) Mappings</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
              <div class="modal-body">
                <template v-for="(value, key, index) in cell_data.mappings">
                    <h3>[[key]]</h3>
                    <div class="card border border-dark shadow" style="overflow-y:auto;max-height:20em">
                        <table width="100%" style="table-layout:fixed;word-wrap: break-word;margin:0;padding:0" class="table table-striped {{config['table-color']}}">
                        <tr>
                            <th style="text-align:left;width:6em;position:-webkit-sticky;position:sticky;top:0"><b>Remove</b></th>
                            <th style="text-align:left;position:-webkit-sticky;position:sticky;top:0"><b>Value</b></th>
                        </tr>
                        <tr v-for="cmd in value">
                            <template v-if="cmd.hasOwnProperty('command')">
                                <td style="text-align:left;width:5em">
                                    <button disabled class="btn btn{{config['outline-buttons']}}danger"><i class="fas fa-trash-alt"></i></button>
                                </td>
                                <td>[[cmd.command]]</td>
                            </template>
                            <template v-else>
                                <td style="text-align:left;width:5em">
                                    <button @click="remove_mapping(cmd.task, cmd.attack)" class="btn btn{{config['outline-buttons']}}danger"><i class="fas fa-trash-alt"></i></button>
                                </td>
                                <td style="text-align:left">Task: <b><a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + cmd.task" target="_blank">[[cmd.task]]</a></b>, [[cmd.task_command]] [[cmd.task_params.substring(0,200)]]</td>
                            </template>
                        </tr>
                    </table>
                    </div><br>
                </template>
              </div>
            <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}primary" data-dismiss="modal" aria-hidden="true">OK</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODEL FOR CLICKED ATT&CK BUTTON -->
{% endblock %}

{% block scripts %}
{% include "mitre_attack_mappings.js" %}
{% endblock %}

{% block body_config %}
tr:nth-child(odd) {
  background-color: {{config['background-color']}};
  color: {{config['text-color']}};
}
{% endblock %}